@inherits BaseEditPlugin

@namespace FluentCMS.Web.Plugins.ContentViewer

@rendermode InteractiveServer

<PluginModalForm Open="Open" Title="Edit Content List Content" Model="@Model" OnSubmit="HandleSubmit" OnCancel="OnCancel" Name="@FORM_NAME">
    <FormSelect Data="ContentTypes" TextField="Title" ValueField="Slug" Placeholder="Choose Content Type" @bind-Value="Model.ContentTypeSlug" Label="Content Type" />
    @if (!string.IsNullOrEmpty(Model.ContentTypeSlug))
    {
        <GridItem Small="GridItemColumn.Twelve">
            <Stack Justify="StackJustify.Start" Items="StackItems.Start" Vertical>
                @{
                    var contentType = ContentTypes.Where(x => x.Slug == Model.ContentTypeSlug).FirstOrDefault();
                }
                <Typography Size="TextSize.Large"></Typography>
                <Typography Size="TextSize.Small"><code class="font-bold">Items</code> variable is available for template, which is list of "@contentType!.Title", Each "@contentType.Title" has these fields:</Typography>
                <Stack Wrap>
                    @foreach (var field in contentType?.Fields ?? [])
                    {
                        <Badge Color="Color.Primary">@field.Name: @field.Type</Badge>   
                    }
                </Stack>
            </Stack>
            <Spacer />                                
        </GridItem>
    }
    <FormTextarea Rows="15" Placeholder="Edit Template" @bind-Value="@Model.Template" Label="Template" />
    <GridItem Small="GridItemColumn.Twelve">
        <Alert Type="AlertType.Info">
            For templating Guide you can refer to <a style="font-weight: bold; text-decoration: underline;" href="https://github.com/scriban/scriban/blob/master/doc/language.md">Scriban's Documentation</a>
        </Alert>
        <Spacer/>
    </GridItem>
</PluginModalForm>
